const fs = require("fs");
const path = require("path");

const arr = [
['id','bigint',''],
['update_date','date','日期'],
['pkg_name','varchar','apk包名'],
['channel','varchar','渠道'],
['display_name','varchar','游戏名'],
['download','bigint','下载次数'],
['launch','bigint','启动次数'],
['splash','bigint','开屏广告次数'],
['reward','bigint','激励视频广告次数'],
['fullvideo','bigint','全屏广告次数'],
['interaction','bigint','插屏广告次数'],
['play_time','bigint','游戏时间,单位秒'],
['register','bigint','注册新增'],
['active','bigint','活跃'],
];

function parse1(arr) {
  let str = ` export type XXX = { `;
  str += arr
    .map((row) => {
      const [name, type, desc] = row;

      // return `
      // /**
      //  * ${desc}
      //  */
      // ${name}:${['float', 'int', 'decimal'].indexOf(type) >= 0 ? 'number' : 'string'}
      // `

      return `"${name}":"${
        ["float", "int", "decimal"].some((v) => type.includes(v)) ? "number" : "string"
      }"`;
    })
    .join(",");

  str += "}";

  fs.writeFileSync(path.join("./", "sql2ts2.ts"), str);
}

function parse2(arr) {
  // id: string
  //     checked: number
  //     key: string
  //     value: string
  //     desc: string
  //     type: string
  //     rtype: string
  //     eg: string
  //     require: number
  //     isBindingGlobalDoc: number
  //     enums: string[]

  const str = arr.map((row) => {
    const [name, type, desc] = row;

    return {
      id: name,
      key: name,
      desc,
      type: ["float", "int", "decimal"].some((v) => type.includes(v))
        ? "number"
        : "string",
    };
  });

  fs.writeFileSync(path.join("./", "sql2ts3.js"), JSON.stringify(str));
}

parse2(arr);
